﻿namespace Community.CsharpSqlite.Entity
{
    /*
    ** An instance of the following structure is used to hold information
    ** about a cell.  The parseCellPtr() function fills in this structure
    ** based on information extract from the raw disk page.
    */
    //typedef struct CellInfo CellInfo;
    public struct CellInfo
    {
        public int iCell; /* Offset to start of cell content -- Needed for C# */
        public ushort iOverflow; /* Offset to overflow page number.  Zero if no overflow */
        public uint nData; /* Number of bytes of data */
        public ushort nHeader; /* Size of the cell content header in bytes */
        public long nKey; /* The key for INTKEY tables, or number of bytes in key */
        public ushort nLocal; /* Amount of payload held locally */
        public uint nPayload; /* Total amount of payload */
        public ushort nSize; /* Size of the cell content on the main b-tree page */
        public byte[] pCell; /* Pointer to the start of cell content */

        public bool Equals(CellInfo ci)
        {
            if (ci.iCell >= ci.pCell.Length || iCell >= pCell.Length) return false;
            if (ci.pCell[ci.iCell] != pCell[iCell]) return false;
            if (ci.nKey != nKey || ci.nData != nData || ci.nPayload != nPayload) return false;
            if (ci.nHeader != nHeader || ci.nLocal != nLocal) return false;
            if (ci.iOverflow != iOverflow || ci.nSize != nSize) return false;
            return true;
        }
    };
}